package com.wlz.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Fanout模式需要声明exchange，并绑定queue，由exchange负责转发到queue上。
 *  广播模式 交换机类型设置为：fanout
 * @author wlz
 * @date 2022-06-29  9:59 下午
 */
@Configuration
public class FanoutConfig {

    @Bean
    public Queue fanoutQueue1() {
        return new Queue("wlz_fanout_queue_1");
    }

    @Bean
    public Queue fanoutQueue2() {
        return new Queue("wlz_fanout_queue_2");
    }

    /**
     *  声明 exchange
     * @return
     */
    @Bean
    public FanoutExchange setFanoutExchange() {
        return new FanoutExchange("wlz_fanout_exchange");
    }


    /**
     *  声明 binding, exchange 与 queue 的绑定关系
     * @return
     */
    @Bean
    public Binding bingQueue1() {
        return BindingBuilder.bind(fanoutQueue1()).to(setFanoutExchange());
    }

    /**
     *  声明 binding, exchange 与 queue 的绑定关系
     * @return
     */
    @Bean
    public Binding bingQueue2() {
        return BindingBuilder.bind(fanoutQueue2()).to(setFanoutExchange());
    }


}
